package cn.xeblog.server.action.specialAc;

import cn.xeblog.commons.entity.User;
import cn.xeblog.commons.entity.react.React;
import cn.xeblog.commons.entity.react.request.AdminReact;
import cn.xeblog.commons.entity.react.result.AdminReactResult;
import cn.xeblog.commons.entity.react.result.ReactResult;
import cn.xeblog.commons.enums.Permissions;
import cn.xeblog.server.action.ChannelAction;
import cn.xeblog.server.action.timer.TimerAction;
import cn.xeblog.server.action.timer.TimerUtil;
import cn.xeblog.server.factory.ReactHandlerFactory;

import java.util.Date;

/**
 * @author ZhangLei
 * @date 2024/2/21 13:39
 */
public interface VoteActionExecute {

    default void doAction(User candidate) {

    }

    default void doAction(User executor, User candidate) {
    }

    @SuppressWarnings("unchecked")
    default void adminReact(AdminReact.Operate operate, String uid) {
        User system = new User();
        system.setIp("127.0.0.1");
        system.setId("11111111111111111111system");
        system.setRole(User.Role.ADMIN);

        ReactResult<AdminReactResult> result = new ReactResult<>();
        ReactHandlerFactory.INSTANCE.produce(React.ADMIN).handle(system, new AdminReact(operate, Permissions.ALL, uid), result);
    }

    default void blockReact(User candidate) {
        TimerUtil.startTimer(new TimerAction() {
            @Override
            public void timingBegins(Date overTime) {
                SpecialCommandHandler.blackControlAdd(candidate);
            }

            @Override
            public void timingEnds(Date overTime) {
                SpecialCommandHandler.blackControlRemove(candidate);
            }
        }, 180);
        ChannelAction.forceOffline(candidate);
    }
}
